import { generateText } from "ai"
import { deepseek } from "@ai-sdk/deepseek"

export async function POST(req: Request) {
  try {
    const { text, targetLanguage } = await req.json()

    if (!text || !targetLanguage) {
      return new Response(JSON.stringify({ error: "Missing text or targetLanguage" }), { status: 400 })
    }

    const { text: translatedText } = await generateText({
      model: deepseek("deepseek-chat"), // Using 'deepseek-chat' for translation
      prompt: `Translate the following English text into ${targetLanguage === "zh" ? "Simplified Chinese" : "English"}: "${text}"`,
      temperature: 0.1,
    })

    return Response.json({ translatedText })
  } catch (error) {
    console.error("Error translating text with DeepSeek:", error)
    return new Response(JSON.stringify({ error: "Failed to translate text" }), { status: 500 })
  }
}
